package com.lianbang.pharmacy.util

import android.content.Context
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import cn.ubest.mvvmcore.utils.ResourcesUtils
import com.lianbang.pharmacy.R

/**
 * Created by maoqi on 2020/12/16.
 */
object EmptyViewUtils {

    fun getEmptyView(
        context: Context?,
        imageRes: Int?,
        text: String?
    ): View {
        return getEmptyView(context, imageRes, text, true)
    }

    /**
     * 返回空页面
     *
     * @param context  context
     * @param type     空页面类型，不同类型的图标和文字不同
     * @param isCenter 图标和文字是否居中
     * @param listener 按钮的监听器
     * @return 空页面
     */
    fun getEmptyView(
        context: Context?,
        imageRes: Int?,
        text: String?,
        isCenter: Boolean
    ): View {
        val view = LayoutInflater.from(context).inflate(R.layout.empty_no_button_layout, null)
        val llContainer = view.findViewById<LinearLayout>(R.id.ll_container)
        if (isCenter) {
            llContainer.gravity = Gravity.CENTER
            llContainer.setPadding(0, 0, 0, 0)
        } else {
            llContainer.gravity = Gravity.CENTER_HORIZONTAL
            llContainer.setPadding(0, ResourcesUtils.getDimens(R.dimen.dp_50), 0, 0)
        }
        val ivImg =
            view.findViewById<ImageView>(R.id.iv_img)
        val tvText = view.findViewById<TextView>(R.id.tv_text)

        imageRes?.also {
            ivImg.setImageResource(it)
        }
        text?.also {
            tvText.text = it
        }
        return view
    }
}